package com.itheima.mall.controller.pmsController;

import com.itheima.mall.commons.R;
import com.itheima.mall.service.pmsService.PmsBrandService;
import com.itheima.pojo.pms.PmsBrand;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/brand")
public class pmsBrandController {

    @Resource
    private PmsBrandService pmsBrandService;

    /**
     * 添加品牌
     */
    @PostMapping("/create")
    public R addBrand(PmsBrand brand) {

        //调用service处理前端传过来的数据
        pmsBrandService.addBrand(brand);
        //返回
        return R.ok("添加成功");
    }

    //删除品牌
    @GetMapping("/delete/{id}")
    public R deleteBrand(@PathVariable(value = "id") Integer id) {
        pmsBrandService.delete(id);
        return R.ok("删除成功");
    }

    //批量删除
    @PostMapping("/delete/batch")
    public R deleteIds(@RequestParam("ids") List<Integer> ids) {
        pmsBrandService.deleteIds(ids);
        return R.ok("删除成功");
    }

    //根据品牌名称查询分类列表
    @GetMapping("/list")
    public R list(String keyword, @RequestParam(defaultValue = "1") Integer pageNum,
                  @RequestParam(defaultValue = "5") Integer pageSize) {
        R pageResult = pmsBrandService.findBrand(keyword,pageNum,pageSize);
        return R.ok(pageResult);
    }

    /**
     * 获取全部品牌列表
     */
    @GetMapping("/listAll")
    public R listAll() {
        List<PmsBrand> list = pmsBrandService.listAll();
        return R.ok(list);
    }

    //批量更新制造商状态
    @PostMapping("/update/factoryStatus")
    public R updateStatus(@RequestParam Integer factoryStatus,@RequestParam List<Long> ids) {
        pmsBrandService.updateStatus(factoryStatus,ids);
        return R.ok("修改成功");
    }

    //批量更新制造商状态
    @PostMapping("/update/showStatus")
    public R updateShowstatus(@RequestParam Integer showStatus,@RequestParam List<Long> ids) {
        pmsBrandService.updateShowstatus(
                showStatus,ids);
        return R.ok("修改成功");
    }

    //更新品牌
    @PostMapping("/update/{id}")
    public R updateBrand(@PathVariable(value = "id")Long id, PmsBrand brand){
        brand.setId(id);
        pmsBrandService.updateBrand(brand);
        return R.ok("更新成功");
    }

    //根据id查询品牌详情
    @GetMapping("/{id}")
    public R findById(@PathVariable(value = "id")Long id) {
        PmsBrand brand = pmsBrandService.findById(id);
        return R.ok(brand);
    }

}